﻿
using Api.Core.IServices.User;
using Api.Core.Model;
using Api.Core.Model.Entity;
using Api.Core.Model.Table;
using Api.Core.Model.User;
using Api.Core.Model.ViewModel;
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Api.Core.Controllers
{

    public class RoleController : BaseController
    {
      
        private readonly IRoleService _roleService;
        private readonly IGroupRoleService _groupService;
        private readonly IMapper _mapper;

        public RoleController(IRoleService roleInfoService, IGroupRoleService groupService,
           IMapper mapper)
        {
            _roleService = roleInfoService;
            _groupService = groupService;
            _mapper = mapper;
        }

        [HttpPost("AddRole")]
        public async Task<BaseResponse<int>> AddRole(RoleViewModel model)
        {
            var role = _mapper.Map<RoleViewModel, RoleTable>(model);
            var intResult = await _roleService.Add(role);
            return Result(intResult);
        }


        [HttpPost("DelRole")]
        public async Task<BaseResponse<bool>> DelRole(RoleViewModel model)
        {
            var role = _mapper.Map<RoleViewModel, RoleTable>(model);
            var blnResult = await _roleService.DeleteById(role.RoleId);
            return Result(blnResult);
        }
    }
}